$(document).ready(
		function() {
			// 滚动加载
			var end = false;
			var page = 0;
			var loading = false; // 状态标记
			if($("#type").val() == 0){
				$('#div1').css('height', $(window).height() - 44);
			} else {
				$('#div1').css('height', $(window).height() - 69);
			}
			$('#div1').pullToRefresh();
			$('#div1').on("pull-to-refresh", function() {
				page = 0;
				end = false;
				loadData(true);
				$('#div1').pullToRefreshDone();
			});
			$('#div1').infinite().on("infinite", function() {
				loadData(false);
			});
			$('#div1').trigger('pull-to-refresh');
			function loadData(type) {
				if (loading)
					return false;
				if (end) {
					return false;
				}
				loading = true;
				$("#loading-div").show();
				$.ajax({
					url : appPath + '/dealer/pageteamdetail.html',
					dataType : 'json',
					data : {
						"page" : page,
						"type" : $("#type").val(),
						"token" : $.cookie("token")
					},
					success : function(result) {
						page = page + 1;
						var pageResult = result.content;
						if (pageResult == null || (pageResult != null && pageResult.length == 0)) {
							end = true;
						}
						var appender = "";
						for (var i = 0; i < pageResult.length; i++) {
							var member = pageResult[i];
							var temStr = '<tr';
							if ($("#type").val() == 0 || $("#type").val() == 1) {
								if(member[6] == 2){
									temStr += ' style="color:red" '
								}
								temStr += ' onclick="seller(' + member[2] + ')"';
							}
							temStr += '><td class="td" style="height:40px;width:30%">';
							if (member[3] != null && member[3] != '' && member[3] != 'null') {
								temStr += member[3];
							} else {
								temStr += member[4];
							}
							temStr += '</td><td class="td" style="height:40px;width:30%">' + member[4]
									+ '</td><td class="td" style="height:40px;width:40%">';
							if ($("#type").val() == 0) {
								var his = member[1] == null || member[1] == 'null' ? 0 : member[0];
								var my = member[0] == null || member[0] == 'null' ? 0 : member[1];
								temStr += his + "/" + my;
							} else {
								var his = member[0] == null || member[0] == 'null' ? 0 : fix(member[0]);
								temStr += his;
							}
							appender += temStr + '</td></tr>';
						}
						$("#loading-div").hide();
						if (type) {
							$("#content").html(appender);
						} else {
							$("#content").append(appender);
						}
						loading = false;
					},
					error : function(XMLHttpRequest, textStatus, errorThrown) {
						$.hideLoading();
						$("#loading-div").hide();
						$.alert("系统异常，请重试");
					}
				});
			}
			$("#select1").change(function() {
				page = 0;
				end = false;
				loadData(true);
				$('#div1').pullToRefreshDone();
			});
			function fix(number) {
				return number * 0.01 - (number * 0.01 - (number * 0.01).toFixed(2));
			}
		});

function seller(id) {
	gotoHtml('/buyer/seller.html?id=' + id);
}